<?php

namespace Admin\Models\sys;

use Helpers\BaseModel;
use Helpers\Main;

class XhsysUploadfile extends BaseModel
{

    /**
     *
     * @var integer
     */
    public $iUFId;

    /**
     *
     * @var string
     */
    public $sFileName;

    /**
     *
     * @var string
     */
    public $sFileType;

    /**
     *
     * @var string
     */
    public $sSuffixName;

    /**
     *
     * @var string
     */
    public $sFileMd5;

    /**
     *
     * @var string
     */
    public $iFileSize;

    /**
     *
     * @var string
     */
    public $sFileId;

    /**
     *
     * @var string
     */
    public $sKeyName;

    /**
     *
     * @var integer
     */
    public $bTimely;

    /**
     *
     * @var integer
     */
    public $bDiscard;

    /**
     *
     * @var integer
     */
    public $bDelete;

    /**
     *
     * @var string
     */
    public $tUploadDate;

    /**
     *
     * @var string
     */
    public $iUploadUserId;

    /**
     * Initialize method for model.
     */
    public function initialize()
    {
        $this->setSource("XHSys_UploadFile");
        $this->addBehavior(new \Phalcon\Mvc\Model\Behavior\SoftDelete(
            array(
                'field' => 'bDelete',
                'value' => 1,
            )
        ));
    }

    /**
     * Returns table name mapped in the model.
     *
     * @return string
     */
    public function getSource()
    {
        return 'XHSys_UploadFile';
    }

    /**
     * Allows to query a set of records that match the specified conditions
     *
     * @param mixed $parameters
     * @return XhsysUploadfile[]
     */
    public static function find($parameters = null)
    {
        return parent::find($parameters);
    }

    /**
     * Allows to query the first record that match the specified conditions
     *
     * @param mixed $parameters
     * @return XhsysUploadfile
     */
    public static function findFirst($parameters = null)
    {
        return parent::findFirst($parameters);
    }

    /**
     * 创建文件上传记录
     *
     * @param $fileName
     * @param $fileType
     * @param $fileSuffix
     * @param $md5Str
     * @param $fileSize
     * @param $url
     * @param $key
     * @return bool
     *
     * create by ck 20170607
     */
    public static function createRecord($fileName, $fileType, $fileSuffix, $md5Str, $fileSize, $url, $key)
    {
        $fileModel = new self();
        $fileModel->sFileName       = $fileName;
        $fileModel->sFileType       = $fileType;
        $fileModel->sSuffixName     = $fileSuffix;
        $fileModel->sFileMd5        = $md5Str;
        $fileModel->iFileSize       = $fileSize;
        $fileModel->sFileId         = $url;
        $fileModel->sKeyName        = $key;
        $fileModel->tUploadDate     = date('Y-m-d H:i:s');
        $fileModel->iUploadUserId   = Main::getLoginUserInfo('userId');
        $fileModel->bTimely         = 0;
        $fileModel->bDiscard        = 0;
        $fileModel->bDelete         = 0;
        return $fileModel->save();
    }

}
